package com.example.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

@RestController
@RequestMapping
public class PortController {
    private HttpServletRequest request;
    private String port;

    @RequestMapping(value = "/hi", method = RequestMethod.GET)
    public String getPort(@RequestParam(value = "name") String name) {
        StringBuilder stringBuilder = new StringBuilder();

        Enumeration<String> headers = request.getHeaderNames();
        while (headers.hasMoreElements()) {
            String headName = headers.nextElement();
            stringBuilder.append(headName + ":" + request.getHeader(headName) + "<br/>");
        }

        return "Hi," + name + ",我的port是：" + port + ",<br/> header:<br/>" + stringBuilder.toString();

    }
}
